﻿using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;

public class RateToolScript {

	/* Interface to native implementation */
	#if UNITY_IOS
	[DllImport ("__Internal")]
	private static extern void _SetGameObjectNameForRT(string gameObjectName);

	[DllImport ("__Internal")]
	private static extern void _RateForID(string id, string alterMessage);

	[DllImport ("__Internal")]
	private static extern bool _HasRated();

	[DllImport ("__Internal")]
	private static extern void _OpenUrl(string url);
	#endif

	public void SetGameObjectNameForRT(string gameObjectName) 
	{
		// Call plugin only when running on real device
		if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) {
			#if UNITY_ANDROID
			SSCInternalAdapter.getInstance().setGameObjName(gameObjectName);
			#elif UNITY_IOS
			_SetGameObjectNameForRT(gameObjectName);
			#endif
		}
	}

	public void RateForID(string id, string alterMessage)
	{
		// Call plugin only when running on real device
		if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) {
			#if UNITY_ANDROID
			SSCInternalAdapter.getInstance().rateUs();
			#elif UNITY_IOS
			_RateForID(id,alterMessage);
			#endif
		}
	}

	public bool HasRated()
	{
		// Call plugin only when running on real device
		if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) {
			#if UNITY_ANDROID
			return SSCInternalAdapter.getInstance().isRated();
			#elif UNITY_IOS
			return _HasRated();
			#endif
		}

		return false;
	}

	public void OpenUrl(string url)
	{
		// Call plugin only when running on real device
		if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) {
			#if UNITY_ANDROID
			SSCInternalAdapter.getInstance().openUrl(url);
			#elif UNITY_IOS
			_OpenUrl(url);
			#endif
		}
	}

}
